﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AdminLogin ad = (AdminLogin)Session["admin"];
                if (ad == null)
                {
                    Response.Redirect("login.aspx");
                }
                else
                {
                    if (ad.pemision == 2)
                    {
                        Response.Redirect("login.aspx");
                    }
                    else
                    {
                        this.Repeater1.DataSource = this.dc.AdminLogins.ToList();
                        this.Repeater1.DataBind();
                    }
                }
            }
        }

        protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("insertaccount.aspx");
        }

        protected void LinkButtonXoa_Click(object sender, EventArgs e)
        {
            AdminLogin add = (AdminLogin)Session["admin"];
            try
            {
                LinkButton lb = (LinkButton)sender;
                HiddenField hd = (HiddenField)lb.Parent.FindControl("HiddenFieldUsername");
                AdminLogin ad = this.dc.AdminLogins.Single(a => a.username == hd.Value);
                if (ad.pemision == add.pemision)
                {
                    this.message_error.Visible = true;
                }
                else
                {

                    this.dc.AdminLogins.DeleteOnSubmit(ad);
                    this.dc.SubmitChanges();

                    this.Repeater1.DataSource = this.dc.AdminLogins.ToList();
                    this.Repeater1.DataBind();
                    this.message_error.Visible = false;
                    this.mesage_success.Visible = true;
                }
            }
            catch
            {
                this.message_error.Visible = false;
                this.mesage_success.Visible = false;
            }


        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            this.message_error.Visible = false;
            this.mesage_success.Visible = false;
        }
    }
}